//
//  GenJinJiLuViewController.m
//  JuBoCRM
//
//  Created by iMac on 2024/2/3.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "GenJinJiLuViewController.h"
#import "ShangChuanTuPianCollectionViewCell.h"
#import "XieGenJinChuanFuJinTableViewCell.h"
#import "XieGenJinFuJianListTableViewCell.h"
#import "NSDate+Helper.h"
#import "XLPhotoBrowser.h"
#import "LiaoTianWenJianChaKanViewController.h"
#import "ZBNetworking.h"
#import "BRStringPickerView.h"
#import "YuYinBoFangView.h"
#import "BRDatePickerView.h"
#import "FaQiShenPiXuanChengYuanViewController.h"
@interface GenJinJiLuViewController ()<UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UITableViewDelegate,UITableViewDataSource,UIDocumentPickerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextViewDelegate>{
    NSMutableArray *imageArray;
    NSMutableArray *fileArray;
    NSString *batchId;
    NSArray *gengJinFangShiArray;
    
    YuYinBoFangView *yuYinView;
}
@property (weak, nonatomic) IBOutlet UICollectionView *tuPianCollectionView;
@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingTableView *mainTableView;

@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingScrollView *mainScrollView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomSpace;
@property (weak, nonatomic) IBOutlet BRPlaceholderTextView *genJinNeiRongTextView;
@property (strong, nonatomic) IBOutletCollection(UIView) NSArray *viewArray;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpace;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *mainCollectionViewHeight;
@property (weak, nonatomic) IBOutlet UITextField *timeTf;
@property (weak, nonatomic) IBOutlet UITextField *fangShiTf;

@property (weak, nonatomic) IBOutlet UILabel *numLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewHeight;
@property (weak, nonatomic) IBOutlet UIView *keHuView;
@property (weak, nonatomic) IBOutlet UITextField *keHuNameTf;
@end

@implementation GenJinJiLuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    
    
    if(_dataInfoDictionary != nil){
        self.customNavBar.title = @"记录编辑";
    }else{
        self.customNavBar.title = @"写记录";
    }
    
    if(_isFromShouYe){
        _keHuView.hidden = NO;
    }else{
        _keHuView.hidden = YES;
    }
    
    [_tuPianCollectionView registerNib:[UINib nibWithNibName:@"ShangChuanTuPianCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ShangChuanTuPianCollectionViewCell"];
 
    [_mainTableView registerNib:[UINib nibWithNibName:@"XieGenJinChuanFuJinTableViewCell" bundle:nil] forCellReuseIdentifier:@"XieGenJinChuanFuJinTableViewCell"];
    
    [_mainTableView registerNib:[UINib nibWithNibName:@"XieGenJinFuJianListTableViewCell" bundle:nil] forCellReuseIdentifier:@"XieGenJinFuJianListTableViewCell"];
    if (@available(iOS 11.0, *)) {
        self.mainScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    _bottomSpace.constant = ScreenBottom+20;
    
    _genJinNeiRongTextView.placeholder = @"请输入跟进内容";
    
    for (UIView *view in _viewArray) {
        view.layer.borderColor = [rgba(223, 223, 223, 1) CGColor];
        view.layer.borderWidth= 0.5;
    }
    _topSpace.constant = NavaBarHeight;
    
    
    if(_dataInfoDictionary != nil){
        if([[_dataInfoDictionary objectForKey:@"img"] isKindOfClass:[NSArray class]]){
            imageArray = [NSMutableArray arrayWithArray:[_dataInfoDictionary objectForKey:@"img"]];
        }else{
            imageArray = [NSMutableArray array];
        }
        
        if(imageArray.count < 9){
            [imageArray addObject:[NSDictionary dictionary]];
        }
        if([[_dataInfoDictionary objectForKey:@"file"] isKindOfClass:[NSArray class]]){
            fileArray = [NSMutableArray arrayWithArray:[_dataInfoDictionary objectForKey:@"file"]];
        }else{
            fileArray = [NSMutableArray array];
        }
    
        if(fileArray.count < 9){
            [fileArray addObject:[NSDictionary dictionary]];
        }
       
        batchId = GetHandleString(_dataInfoDictionary, @"batchId");
        if(batchId.length == 0){
            NSString *time = [NSString stringWithFormat:@"%@%@%@%@",[ZZPUtils getTimeStamp],[ZZPUtils getTimeStamp],[ZZPUtils getTimeStamp],[ZZPUtils getTimeStamp]];
            
            batchId = [time substringToIndex:32];
        }
        _numLabel.text = [NSString stringWithFormat:@"%ld/500",[GetHandleString(_dataInfoDictionary, @"content") length]];
        _genJinNeiRongTextView.text = GetHandleString(_dataInfoDictionary, @"content");
        _fangShiTf.text = GetHandleString(_dataInfoDictionary, @"category");
        _timeTf.text = GetHandleString(_dataInfoDictionary, @"nextTime");
        
        [_mainTableView reloadData];
        [_tuPianCollectionView reloadData];
        
    }else{
        imageArray = [NSMutableArray array];
        [imageArray addObject:[NSDictionary dictionary]];
        
        fileArray = [NSMutableArray array];
        [fileArray addObject:[NSDictionary dictionary]];
        
        NSString *time = [NSString stringWithFormat:@"%@%@%@%@",[ZZPUtils getTimeStamp],[ZZPUtils getTimeStamp],[ZZPUtils getTimeStamp],[ZZPUtils getTimeStamp]];
        
        batchId = [time substringToIndex:32];
    }
    
    
    

    [self sheZhiFuJianShiTuGaoDu];
    [self sheZhiTuPianShiTuGaoDu];
    
    [self huoQuGenJinFangShi];
    
    yuYinView = [YuYinBoFangView view];
    [[AppDelegate shareInstance].window addSubview:yuYinView];
  
    yuYinView.frame = CGRectMake(0, ScreenHeight-107-30, ScreenWidth, 107);
    yuYinView.hidden = YES;
    
  
}
- (void)viewWillDisappear:(BOOL)animated{
    yuYinView.hidden = YES;
    [yuYinView closeVoice];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    // 获取当前文本框中的文本
 
    NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
    
    // 设置最大字符长度
    NSUInteger maxLength = 500;
    
    _numLabel.text = [NSString stringWithFormat:@"%ld/%ld",textView.text.length,maxLength];
    
    // 检查是否超过最大长度
    if (newText.length <= maxLength) {
        return YES; // 允许输入
    } else {
        return NO; // 超过最大长度，禁止输入
    }
}


//获取跟进方式
- (void)huoQuGenJinFangShi{
    [[ZZPRequest getWebUtil] postNetworkRequestURLString:@"/crmActionRecord/queryRecordOptions" andParas:nil andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            gengJinFangShiArray = [info objectForKey:@"data"];
        }
    }];
}


//设置选图片高度
- (void)sheZhiTuPianShiTuGaoDu{
    NSInteger row = imageArray.count/3;
    if(imageArray.count%3 != 0){
        row++;
    }
    _mainCollectionViewHeight.constant = row*(((ScreenWidth-16)/3-16)*78/104+16);
}
//设置附件视图高度
- (void)sheZhiFuJianShiTuGaoDu{
    if([[[fileArray lastObject] allValues] count] > 0){
        _tableViewHeight.constant = fileArray.count*52;
    }else{
        _tableViewHeight.constant = (fileArray.count-1)*52+92+8;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return fileArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dataDic = fileArray[indexPath.row];
    if([[dataDic allKeys] count] > 0){
        XieGenJinFuJianListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XieGenJinFuJianListTableViewCell"];
        cell.nameLabel.text = GetHandleString(dataDic, @"name");
        cell.sizeLabel.text = [self fileSizeConversion:[GetHandleString(dataDic, @"size") integerValue]];
        [cell.xiaZaiButton setTitle:@"删除" forState:UIControlStateNormal];
        cell.manageClickBlock = ^(NSInteger index) {
            if(index == 101){
//                预览
                if([GetHandleString(dataDic, @"urlImage") containsString:@".mp3"]){
                    yuYinView.hidden = NO;
                    yuYinView.titleLabel.text = GetHandleString(dataDic, @"name");
                    yuYinView.voiceUrl = GetHandleString(dataDic, @"urlImage");
                }else{
                    LiaoTianWenJianChaKanViewController *yuLan = [[LiaoTianWenJianChaKanViewController alloc] init];
                    yuLan.loadUrl = GetHandleString(dataDic, @"urlImage");
                    [self pushViewController:yuLan];
                }
                
            }else if(index == 102){
//               删除
                [self shanChuWenJianWithDic:dataDic andIsImage:NO];
            }
        };
        return cell;
    }
    XieGenJinChuanFuJinTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XieGenJinChuanFuJinTableViewCell"];
    return cell;
}

//将文件大小转换为 M/KB/B
- (NSString *)fileSizeConversion:(NSInteger)totalSize {
    NSString *totleStr = nil;
    if (totalSize > 1024 * 1024) {
        totleStr = [NSString stringWithFormat:@"%.2fM",totalSize / 1024.00f /1024.00f];
    } else if (totalSize > 1024) {
        totleStr = [NSString stringWithFormat:@"%.2fKB",totalSize / 1024.00f ];
        
    } else {
        totleStr = [NSString stringWithFormat:@"%.2fB",totalSize / 1.00f];
    }
    return totleStr;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dataDic = fileArray[indexPath.row];
    if([[dataDic allKeys] count] > 0){
        return 52;
    }
    return 92;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dataDic = fileArray[indexPath.row];
    if([[dataDic allValues] count] == 0){
        [self selectiCloudFile];
    }
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return imageArray.count;
}
//创建cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ShangChuanTuPianCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ShangChuanTuPianCollectionViewCell" forIndexPath:indexPath];
    NSDictionary *dataDic = imageArray[indexPath.row];
    if([[dataDic allValues] count] > 0){
        cell.deleteButton.hidden = NO;
        [cell.itemImage sd_setImageWithURL:WebImagePath(GetHandleString(dataDic, @"urlImage"))];
    }else{
        cell.deleteButton.hidden = YES;
        cell.itemImage.image = LocalImagePath(@"跟进记录上传图片");
    }
    
    cell.deleteClickBlock = ^{
//        删除
        [self shanChuWenJianWithDic:dataDic andIsImage:YES];
    };
    return cell;
}

//设置item的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    return CGSizeMake(120, 86);
    return CGSizeMake((ScreenWidth-16)/3, ((ScreenWidth-16)/3-16)*78/104+16);
}
//设置垂直间距,默认的垂直和水平间距都是10
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
//设置水平间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}

//四周的边距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 8, 0, 8);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dataDic = imageArray[indexPath.row];
    if([[dataDic allValues] count] == 0){
//       添加
        [self shangChuanTuPian];
    }else{
        [XLPhotoBrowser showPhotoBrowserWithImages:@[GetHandleString(dataDic, @"urlImage")] currentImageIndex:0];
    }
}

//删除文件
- (void)shanChuWenJianWithDic:(NSDictionary *)dataDic andIsImage:(BOOL)isImage{
    NSString *url = [NSString stringWithFormat:@"/adminFile/deleteById/%@",GetHandleString(dataDic, @"fileId")];
    [[ZZPRequest getWebUtil] postNetworkRequestURLString:url andParas:nil andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            if (isImage) {
                [imageArray removeObject:dataDic];
                NSDictionary *dataDic = imageArray.lastObject;
                if([[dataDic allValues] count] > 0){
                    [imageArray addObject:[NSDictionary dictionary]];
                }
                [UIView performWithoutAnimation:^{
                    [_tuPianCollectionView reloadData];
                }];
                [self sheZhiTuPianShiTuGaoDu];
            }else{
                [fileArray removeObject:dataDic];
                NSDictionary *dataDic = fileArray.lastObject;
                if([[dataDic allValues] count] > 0){
                    [fileArray addObject:[NSDictionary dictionary]];
                }
                
                [UIView performWithoutAnimation:^{
                    [_mainTableView reloadData];
                }];
                
                [self sheZhiFuJianShiTuGaoDu];
            }
        }
    }];
}


//上传图片
- (void)shangChuanTuPian{
    
    [self.view endEditing:YES];
    
    SPAlertController *alertController = [SPAlertController alertControllerWithTitle:nil message:nil preferredStyle:SPAlertControllerStyleActionSheet];
    SPAlertAction *action1 = [SPAlertAction actionWithTitle:@"拍摄" style:SPAlertActionStyleDefault handler:^(SPAlertAction * _Nonnull action) {
         //拍照
         [self takePhoto];
    }];
    [alertController addAction:action1];
    action1.titleColor = mainFontColor;
    action1.titleFont = [UIFont systemFontOfSize:17];
    SPAlertAction *action2 = [SPAlertAction actionWithTitle:@"从相册选择" style:SPAlertActionStyleDefault handler:^(SPAlertAction * _Nonnull action) {
        //相册
        [self LocalPhoto];
    }];
    [alertController addAction:action2];
    action2.titleColor = mainFontColor;
    action2.titleFont = [UIFont systemFontOfSize:17];
    SPAlertAction *cancel = [SPAlertAction actionWithTitle:@"取消" style:SPAlertActionStyleCancel handler:^(SPAlertAction * _Nonnull action) {
    }];
    [alertController addAction:cancel];
    cancel.titleColor = mainFontColor;
    cancel.titleFont = [UIFont systemFontOfSize:17];
    [self presentViewController:alertController animated:YES completion:nil];
}


//上传文件
- (void)shangChuanWenJianWithParaDic:(NSDictionary *)paraDic andIsImage:(BOOL)isImage andDataArray:(NSArray *)dataArray{
    [[ZZPRequest getWebUtil] uploadImageRequestURLString:@"/adminFile/upload" andParas:paraDic andImageArray:dataArray andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            NSDictionary *data = [info objectForKey:@"data"];
            if(isImage){
                [imageArray removeLastObject];
                [imageArray addObject:data];
                if(imageArray.count < 9){
                    [imageArray addObject:[NSDictionary dictionary]];
                }
                [UIView performWithoutAnimation:^{
                    [_tuPianCollectionView reloadData];
                }];
                [self sheZhiTuPianShiTuGaoDu];
            }else{
                [fileArray removeLastObject];
                [fileArray addObject:data];
                if(fileArray.count < 9){
                    [fileArray addObject:[NSDictionary dictionary]];
                }
                [UIView performWithoutAnimation:^{
                    [_mainTableView reloadData];
                }];
                [self sheZhiFuJianShiTuGaoDu];
               
            }
           
        }
    }];
}

//开始拍照
- (void)takePhoto
{
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//        [[picker navigationBar] setBarTintColor:[UIColor whiteColor]];
        picker.delegate = self;
        picker.allowsEditing = NO;
        picker.sourceType = sourceType;
        [self presentViewController:picker animated:YES completion:^{
            self.navigationController.navigationBar.barStyle = UIBarStyleDefault;

        }];
    }else
    {
        NSLog(@"模拟其中无法打开照相机,请在真机中使用");
    }
}
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:@"public.image"])
    {
        UIImage * image;
        if (picker.allowsEditing) {
            image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
        }else
        {
            image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        }
        NSData * imageData = UIImageJPEGRepresentation(image, 0.05);

        NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
        [tempDic setValue:imageData forKey:@"data"];
        [tempDic setValue:[NSString stringWithFormat:@"%f.png",[[NSDate date] timeStamp]] forKey:@"name"];
        NSArray *array = @[tempDic];
        
        NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
        [paraDic setValue:@"img" forKey:@"type"];
        [paraDic setValue:batchId forKey:@"batchId"];
        
        [self shangChuanWenJianWithParaDic:paraDic andIsImage:YES andDataArray:array];
        
        
        
        [picker dismissViewControllerAnimated:YES completion:nil];
    }
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{

}
//打开本地相册
- (void)LocalPhoto{
    NSInteger maxNum = 10 - imageArray.count;
    TZImagePickerController *imagePickerVc=[[TZImagePickerController alloc] initWithMaxImagesCount:maxNum columnNumber:4 delegate:nil pushPhotoPickerVc:YES];

    imagePickerVc.oKButtonTitleColorNormal = rgba(24, 27, 37, 1);
    imagePickerVc.naviBgColor = [UIColor whiteColor];
    imagePickerVc.naviTitleColor = rgba(24, 27, 37, 1);
    imagePickerVc.barItemTextColor = rgba(24, 27, 37, 1);
    
//    imagePickerVc.selectedAssets=_selectAsssts;
    imagePickerVc.selectedAssets=nil;
    //不允许 选择 视频和gif 动图 如需要 自行设置
    imagePickerVc.allowPickingVideo=NO;
    imagePickerVc.allowPickingGif=NO;
    imagePickerVc.allowPreview=NO;
   
    imagePickerVc.allowCrop = YES;

    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {

        for (UIImage *img in photos) {
            
            NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
            [tempDic setValue:UIImageJPEGRepresentation(img, 0.5) forKey:@"data"];
            [tempDic setValue:[NSString stringWithFormat:@"%f.png",[[NSDate date] timeStamp]] forKey:@"name"];
            NSArray *array = @[tempDic];
            
            NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
            [paraDic setValue:@"img" forKey:@"type"];
            [paraDic setValue:batchId forKey:@"batchId"];
            
            [self shangChuanWenJianWithParaDic:paraDic andIsImage:YES andDataArray:array];
            
        }

    }];
    imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:imagePickerVc animated:YES completion:nil];
}


#pragma mark - UIDocumentPickerDelegate
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
    //获取授权
    BOOL fileUrlAuthozied = [urls.firstObject startAccessingSecurityScopedResource];
    if (fileUrlAuthozied) {
        //通过文件协调工具来得到新的文件地址，以此得到文件保护功能
        NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
        NSError *error;
        
        [fileCoordinator coordinateReadingItemAtURL:urls.firstObject options:0 error:&error byAccessor:^(NSURL *newURL) {
            //读取文件
            NSString *fileName1 = [newURL lastPathComponent];
            NSError *error = nil;
            NSData *fileData = [NSData dataWithContentsOfURL:newURL options:NSDataReadingMappedIfSafe error:&error];
            if (error) {
                //读取出错
            } else {
                //文件 上传或者其它操作
//                [self uploadingWithFileData:fileData fileName:fileName fileURL:newURL];
                
                NSLog(@"------------->文件 上传或者其它操作");
                
                long long currentTime = [[NSDate date] timeIntervalSince1970] * 1000;

                NSString *fileName = [NSString stringWithFormat:@"/file_%@/%@", @(currentTime),fileName1];

                NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
                [tempDic setValue:fileData forKey:@"data"];
                [tempDic setValue:fileName forKey:@"name"];
                NSArray *array = @[tempDic];
                
                NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
                [paraDic setValue:@"file" forKey:@"type"];
                [paraDic setValue:batchId forKey:@"batchId"];
                
                [self shangChuanWenJianWithParaDic:paraDic andIsImage:NO andDataArray:array];

            }
            [self dismissViewControllerAnimated:YES completion:NULL];
        }];
        [urls.firstObject stopAccessingSecurityScopedResource];
    } else {
        //授权失败
    }
}
- (void)selectiCloudFile{
    [self.view endEditing:YES];
//    NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code", @"public.image", @"public.audiovisual-content", @"com.adobe.pdf", @"com.apple.keynote.key", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt"];
    NSArray *documentTypes = @[ @"public.image", @"public.mp3", @"com.adobe.pdf", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt",@"org.openxmlformats.wordprocessingml.document"];
    UIDocumentPickerViewController *documentPickerViewController = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeOpen];
    documentPickerViewController.delegate = self;
    documentPickerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:documentPickerViewController animated:YES completion:nil];
}

- (void)fileDidSelect:(NSArray *)filePathList{
    
}
//跟进方式
- (IBAction)fangShi:(UITapGestureRecognizer *)sender {
    [self.view endEditing:YES];
    
    BRStringPickerView *datePickerView = [[BRStringPickerView alloc]init];
    datePickerView.pickerMode = BRStringPickerComponentSingle;
    datePickerView.title = @"";
    datePickerView.dataSourceArr = gengJinFangShiArray;
    datePickerView.selectValue = _fangShiTf.text;
    //    strPickerView.isAutoSelect = isAutoSelect;
    datePickerView.resultModelBlock = ^(BRResultModel *resultModel) {
        NSLog(@"选择的索引：%@", @(resultModel.index));
        NSLog(@"选择的值：%@", resultModel.value);
        
        _fangShiTf.text = resultModel.value;
        
    };
    
    BRPickerStyle *customStyle = [[BRPickerStyle alloc]init];
    customStyle.pickerColor = [UIColor whiteColor];
    customStyle.selectRowTextColor = rgba(40, 120, 255, 1);
    customStyle.titleBarColor = [UIColor whiteColor];
    customStyle.titleTextColor = [UIColor whiteColor];
    customStyle.cancelTextColor = rgba(153, 153, 153, 1);
    customStyle.doneTextColor = rgba(40, 120, 255, 1);
    customStyle.titleBarHeight = 48;
    customStyle.titleTextFont = [UIFont systemFontOfSize:18];
    datePickerView.pickerStyle = customStyle;
    customStyle.topCornerRadius = 10;
    customStyle.hiddenTitleLine = YES;
    customStyle.separatorColor = rgba(223, 229, 242, 1);
    customStyle.separatorHeight = 0.5;
    customStyle.rowHeight = 64;
    
    [datePickerView show];
    
    
}

//时间
- (IBAction)shiJian:(UITapGestureRecognizer *)sender {
    [self.view endEditing:YES];
    
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
    datePickerView.pickerMode = BRDatePickerModeYMDHMS;
    datePickerView.title = @"";
    datePickerView.minDate = [NSDate date];
    datePickerView.maxDate = nil;
    
    datePickerView.isAutoSelect = NO;

    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
   
        NSLog(@"selectValue=%@", selectValue);
        NSLog(@"selectDate=%@", selectDate);
        NSLog(@"---------------------------------");
        _timeTf.text = selectValue;
        
    };
 
    BRPickerStyle *customStyle = [[BRPickerStyle alloc]init];
    customStyle.pickerColor = [UIColor whiteColor];
    customStyle.selectRowTextColor = rgba(51, 51, 51, 1);
    customStyle.titleBarColor = [UIColor whiteColor];
    customStyle.titleTextColor = [UIColor whiteColor];
    customStyle.cancelTextColor = rgba(153, 153, 153, 1);
    customStyle.doneTextColor = rgba(40, 120, 255, 1);
    customStyle.titleBarHeight = 48;
    customStyle.titleTextFont = [UIFont systemFontOfSize:18];
    datePickerView.pickerStyle = customStyle;
    customStyle.topCornerRadius = 10;
    customStyle.hiddenTitleLine = YES;
    customStyle.separatorColor = rgba(223, 229, 242, 1);
    customStyle.separatorHeight = 0.5;
    customStyle.rowHeight = 64;

    [datePickerView show];
    
}
//选客户
- (IBAction)xuanKeHu:(UITapGestureRecognizer *)sender {
    FaQiShenPiXuanChengYuanViewController *xuan = [[FaQiShenPiXuanChengYuanViewController alloc] init];
    xuan.isFromGenJin = YES;
    xuan.manageClickResultBlock = ^(NSString * _Nonnull resultName, NSString *resultId) {
        _activityTypeId = resultId;
        _keHuNameTf.text = resultName;
    };
    [self pushViewController:xuan];
}

//确定
- (IBAction)queDing:(UIButton *)sender {
    [self.view endEditing:YES];
    if(_genJinNeiRongTextView.text.length == 0){
        [ZZPUtils showWarning:_genJinNeiRongTextView.placeholder];
        return;
    }
    
//    if(_timeTf.text.length == 0){
//        [ZZPUtils showWarning:@"请选择下次联系时间"];
//        return;
//    }
    
    if(_fangShiTf.text.length == 0){
        [ZZPUtils showWarning:@"请选择跟进方式"];
        return;
    }
    
    if(_activityTypeId.length == 0){
        [ZZPUtils showWarning:@"请先选择客户"];
        return;
    }
    
    
    
    NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
    [paraDic setValue:@"2" forKey:@"activityType"];
    [paraDic setValue:_activityTypeId forKey:@"activityTypeId"];
    [paraDic setValue:_genJinNeiRongTextView.text forKey:@"content"];
    [paraDic setValue:_fangShiTf.text forKey:@"category"];
    [paraDic setValue:batchId forKey:@"batchId"];
    [paraDic setValue:@"" forKey:@"businessIds"];
    [paraDic setValue:@"" forKey:@"contactsIds"];
    [paraDic setValue:_timeTf.text forKey:@"nextTime"];
    [paraDic setValue:@"0" forKey:@"isEvent"];
    NSString *url = @"/crmActivity/addCrmActivityRecord";
    if(_dataInfoDictionary != nil){
        [paraDic setValue:GetHandleString(_dataInfoDictionary, @"activityId") forKey:@"activityId"];
        url = @"/crmActivity/updateActivityRecord";
    }
    [[ZZPRequest getWebUtil] postJsonNetworkRequestURLString:url andParas:paraDic andShowHud:YES andTransferGottenData:^(id info, NSError *error) {
        if(!error){
            if(_dataInfoDictionary != nil){
                [ZZPUtils showWarning:@"编辑成功"];
            }else{
                [ZZPUtils showWarning:@"添加成功"];
            }
            if(_addSuccessClickBlock){
                _addSuccessClickBlock();
            }
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

 
